package com.web.expspringboot.mapper;

import com.web.expspringboot.entity.UserSt;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    // 插入新用户
    @Insert("INSERT INTO user_st (user_id, user_name, user_account, user_password, user_banned, is_manager) " +
            "VALUES (#{userId}, #{userName}, #{userAccount}, #{userPassword}, #{userBanned}, #{isManager})")
    void insertUser(UserSt user);

    // 根据用户ID删除用户
    @Delete("DELETE FROM user_st WHERE user_id = #{userId}")
    void deleteUserById(long userId);

    // 更新用户信息
    @Update("UPDATE user_st SET user_name = #{userName}, user_account = #{userAccount}, " +
            "user_password = #{userPassword}, user_banned = #{userBanned}, is_manager = #{isManager} " +
            "WHERE user_id = #{userId}")
    boolean updateUser(UserSt user);

    // 根据用户ID查询用户
    @Select("SELECT " +
            "user_id AS userID, " +
            "user_name AS userName, " +
            "user_account AS userAccount, " +
            "user_password AS userPassword, " +
            "user_banned AS userBanned, " +
            "is_manager AS isManager " +
            "FROM user_st WHERE user_account = #{phoneNum}")
    UserSt selectUserByPhoneNum(String phoneNum);

    //查询全部用户
    @Select("SELECT " +
            "user_id AS userID, " +
            "user_name AS userName, " +
            "user_account AS userAccount, " +
            "user_password AS userPassword, " +
            "user_banned AS userBanned, " +
            "is_manager AS isManager " +
            "FROM user_st")
    List<UserSt> getAllUser();
}
